<template>
  <div>
    <van-pull-refresh v-model="refreshing" @refresh="onRefresh">
    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
    >
      <article-item v-for="obj in articleList" :key="obj.art_id" :artObj="obj">
      </article-item>
    </van-list>
    </van-pull-refresh>
  </div>
</template>

<script>
import ArticleItem from './components/ArticleItem.vue'
import { getArticleListAPI } from '@/api'
export default {
  data () {
    return {
      articleList: [],
      list: [],
      loading: false,
      finished: false,
      times: new Date(),

      refreshing: false
    }
  },
  methods: {
    onLoad () {
      // 异步更新数据
      this.getArticleList()
    },
    onRefresh () {
      this.articleList = []
      this.times = new Date()
      this.getArticleList()
    },
    async getArticleList () {
      const res = await getArticleListAPI({ channel_id: this.channelId, timestamp: this.times })
      this.articleList = res.data.data.results
      this.times = res.data.data.pre_timestamp
      console.log(res)
      this.loading = false
      if (res.data?.data?.pre_timestamp === null) {
        this.finished = true
      }
      setTimeout(() => {
        this.refreshing = false
      }, 1000)
    }

  },
  props: {
    channelId: Number
  },
  components: {
    ArticleItem
  },
  created () {
    // 获取文章
    this.getArticleList()
  }
}
</script>

<style>
</style>
